﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using QuanLyBanHang.OBJECT;
using System.Data.SqlClient;
namespace QuanLyBanHang.DAL
{
    static class DalNhaCungCap
    {
        public static DataTable LoadSupplier()
        {
            string sql = "Select MaNCC,Ten,DiaChi,SoDienThoai,Email from NhaCungCap where TrangThai=1";
            DataTable dt = DataHelper.Load(sql);
            return dt;
        }
        public static DataTable GetID()
        {
            string sql = "select top 1 MaNCC from NhaCungCap order by MaNCC desc";
            DataTable dt = DataHelper.Load(sql);
            return dt;
        }
        public static int InsertSupplier(ObjNhaCungCap obj)
        {
            SqlParameter[] para = new SqlParameter[5];
            string[] names = { "MaNCC", "Ten", "DiaChi", "SoDienThoai", "Email" };
            object[] values = { obj.MaNCC, obj.Ten, obj.DiaChi, obj.SoDienThoai, obj.Email };
            for (int i = 0; i < para.Length; i++)
            {
                para[i] = new SqlParameter(names[i], values[i]);
            }
            int thucthi = DataHelper.Update(para, "spInsertNhaCC");
            return thucthi;
        }
        public static int UpdateSupplier(ObjNhaCungCap obj)
        {
            SqlParameter[] para = new SqlParameter[5];
            string[] names = { "MaNCC", "Ten", "DiaChi", "SoDienThoai", "Email" };
            object[] values = { obj.MaNCC, obj.Ten, obj.DiaChi, obj.SoDienThoai, obj.Email };
            for (int i = 0; i < para.Length; i++)
            {
                para[i] = new SqlParameter(names[i], values[i]);
            }
            int thucthi = DataHelper.Update(para, "spUpdateNhaCC");
            return thucthi;
        }
        public static int DeleteSupplier(string MaNCC)
        {
            SqlParameter[] para = { new SqlParameter("MaNCC", MaNCC) };
            int thucthi = DataHelper.Update(para, "spDeleteNhaCC");
            return thucthi;
        }
    }
}
